<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">

    <link rel="stylesheet" href="bootstrap-3.3.4/dist/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="Flat-UI-master/dist/css/flat-ui.min.css"/>
    <script src="bootstrap-3.3.4/dist/js/jquery-3.5.1.min.js"></script>
    <script src="bootstrap-3.3.4/dist/js/jquery.cookie-1.4.1.min.js"></script>
    <script src="bootstrap-3.3.4/dist/js/bootstrap.min.js"></script>
    <script src="Flat-UI-master/dist/js/flat-ui.min.js"></script>
    <script src="custom/util.js"></script>

    <title>创建订单</title>
    <style>
        .row {
            margin-left: 20px;
            margin-right: 20px;;
        }
    </style>
</head>


<body>
<script>
    $(function () {
        // 允许跨域传cookie
        $.ajaxSetup({crossDomain: true, xhrFields: {withCredentials: true}});

        $("button").click(function () {
            $.ajax({
                url: url + "/order/sender/publish",
                type: "POST",
                contentType: "application/json; charset=utf-8", // post请求必须设置这个
                data: JSON.stringify({
                    description: $("input#description").val(),
                    when: $("input#when").val(),
                    location: $("input#location").val(),
                    price: $("input#price").val(),
                    comment: $("input#comment").val()
                }),
                // async: false,
                success: function (res) {
                    if (res.flag === 2000) {
                        location.assign("Order.html"); // 跳到我的订单
                    } else {
                        alert(res.data);
                    }
                },
                error: function () {
                    alert("创建订单错误，请联系开发者解决问题")
                }
            });
        })

        // 注销
        $("#logout").click(function () {
            $("#logout").hide();
            $("#register").show();
            $("#login").show();
            $.ajax({
                url: url + "/user/logout",
                success: function (data) {
                    console.log("log out success")
                },
                error: function () {
                    console.log("error");
                }
            });
        });

        // // 查看当前登录状态
        // if ($.cookie("JSESSIONID") === null) {
        //     $("#register").show();
        //     $("#login").show();
        // } else {
        //     $("#logout").show();
        // }

        // 老的方式，再次使用
        $.ajax({
            url: url + "/user/check",
            success: function (data) {
                if (data["flag"] === 2000) {
                    // 已经登录了
                    $("#logout").show();
                } else {
                    // 还没登录
                    $("#register").show();
                    $("#login").show();
                }
            },
            error: function () {
                console.log("error");
            }
        });
    });

</script>


<!-- Static navbar -->
<div class="navbar navbar-default navbar-static-top" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">这什么东西</span>
            </button>
            <a class="navbar-brand" href="Index.html">快递代取系统</a>
        </div>
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li><a href="Index.html">首页</a></li>
                <li class="active"><a href="NewOrder.html">创建订单</a></li>
                <li><a href="Order.html">我的订单</a></li>
                <li><a href="PickedOrder.html">我的接单</a></li>
                <li><a href="UserInfo.html">个人中心</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right hidden-sm">
                <li><a id="login" href="Login.html" style="display: none;">登录</a></li>
                <li><a id="register" href="Register.html" style="display: none">注册</a></li>
                <li><a id="logout" href="#" style="display: none">注销</a></li>
                <li>
                    <a href="Cart.html"><span class="glyphicon glyphicon-shopping-cart">购物车</span></a>
                </li>
            </ul>
        </div><!--/.nav-collapse -->
    </div>
</div>
<!--content-->
<div class="container">
    <div class="row thumbnail">
        <div class="col-sm-12">
            <h1 class="text-center" style="margin-bottom: 30px">创建新订单</h1>
        </div>

        <div class="col-sm-12">
            <form class="form-horizontal caption" action="https://www.baidu.com" method="post" onsubmit="return false;">

                <div class="form-group">
                    <label for="description" class="col-sm-3 control-label">订单描述</label>
                    <div class="col-sm-6">
                        <input type="text" name="description" class="form-control" id="description"
                               placeholder="这是一个不错的订单">
                    </div>
                </div>

                <div class="form-group">
                    <label for="when" class="col-sm-3 control-label">什么时候送到？</label>
                    <div class="col-sm-6">
                        <input type="datetime-local" name="when" class="form-control" id="when"
                               value="2022-02-22T13:45:00">
                    </div>
                </div>


                <div class="form-group">
                    <label for="location" class="col-sm-3 control-label">送到哪里？</label>
                    <div class="col-sm-6">
                        <input type="text" name="location" class="form-control" id="location" placeholder="第八宿舍">
                    </div>
                </div>

                <div class="form-group">
                    <label for="price" class="col-sm-3 control-label">价格</label>
                    <div class="col-sm-6">
                        <input type="number" name="price" class="form-control" id="price" placeholder="1块钱">
                    </div>
                </div>

                <div class="form-group">
                    <label for="comment" class="col-sm-3 control-label">备注</label>
                    <div class="col-sm-6">
                        <input type="text" name="comment" class="form-control" id="comment" placeholder="贵重物品">
                    </div>
                </div>


                <!-- 提示信息:  -->
                <div class="form-group">
                    <div class="col-sm-offset-3 col-sm-8">
                        <p id="common" style="font-size: 10px; display: none;">&nbsp;&nbsp;&nbsp;<b>msg</b></p>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-4 col-sm-4">
                        <button type="submit" class="btn btn-success btn-block">提交</button>
                    </div>
                </div>
            </form>
        </div>

        <!--        <div class="col-sm-6">-->
        <!--            <div class="caption">-->
        <!--                <h3>免责声明</h3>-->
        <!--                <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>-->

        <!--            </div>-->

        <!--        </div>-->
    </div>
</div>


<!--footer-->
<div class="navbar navbar-default navbar-static-bottom">
    <p style="text-align: center">版权声明区</p>
</div>
</body>
</html>